<template>
  <div class="home-page body">
    <!-- {{activeIndex}} -->
    <van-tabs animated v-model="activeIndex">
      <van-tab v-for="channel in channelList" :title="channel.name" :key="channel.id">
        <article-list :cid="channel.id"></article-list>
      </van-tab>
    </van-tabs>
    <!-- 按钮 -->
    <div class="btn-wrapper">
      <geek-icon name="search"></geek-icon>
      <!--
        native 将自己封装的组件上 可以按照 原始DOM元素 执行事件
       -->
      <geek-icon name="channel" @click.native="showChannels"></geek-icon>
    </div>

    <!-- 频道页面 -->
    <!-- <article-channels ref="channels"></article-channels> -->
    <article-channels v-if="channelList.length>0" :mychannels="channelList" v-model="isShow" :activeIndex.sync="activeIndex"></article-channels>
  </div>
</template>
<script>
// import { login } from '@/api/user'
// console.log(login)
import { getUserChannels } from '@/api/user'
import articleList from './components/articleList.vue'
import articleChannels from './components/article-channels.vue'
export default {
  name: 'home',
  components: {
    articleList,
    articleChannels
  },
  data () {
    return {
      channelList: [],
      isShow: false,
      activeIndex: 0
    }
  },
  methods: {
    changeIndex (index) {
      this.activeIndex = index
    },
    showChannels () {
      this.isShow = true
    }
  },
  async created () {
    // const [err, data] = await login('17303837878', '123456')
    // if (err) console.log('失败', err.message)
    // else console.log(data)

    this.channelList = await getUserChannels()
    // if (err) return this.$toast.fail(err)
    // this.channelList = data.channels
  }
}
</script>
<style scoped lang="less">
::v-deep .van-tabs {
   height: 100%;
  display: flex;
  flex-direction: column;
  .van-tabs__line {
    background: @geek-color;
    height: 2px;
    width: 32px;
  }
  .van-tab {
    color: #9EA1AE;
  }
  .van-tab--active {
    font-size: 18px;
    color: #333;
  }
  .van-tabs__wrap {
    padding-right: 86px;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
  }
  .van-tabs__content {
    flex: 1;
    overflow: hidden;
  }
  .van-tab__pane {
    height: 100%;
  }
}

.home-page {
  .btn-wrapper {
    position: absolute;
    right: 0;
    top: 0;
    width: 86px;
    height: 44px;
    background: #fff;
    display: flex;
    align-items: center;
    .geek-icon {
      flex: 1;
      text-align: center;
      font-size: 18px;
    }
    &::before {
      content: "";
      width: 20px;
      height: 44px;
      position: absolute;
      left: -20px;
      top: 0;
      background: linear-gradient(to right, rgba(255,255,255,0), #fff);
    }
  }
}
</style>
